package vfs.persist.association.impl;

import java.sql.Connection;
import java.util.Iterator;
import vfs.filter.VFSFilter;
import vfs.obj.entity.VFSNode;
import vfs.obj.entity.VFSUser;
import vfs.persist.association.VFSAssociationManager;
import vfs.persist.association.VFSUserToHomeDirectoryManager;
import vfs.persist.entity.build.impl.VFSNodeBuilder;
import vfs.persist.entity.build.impl.VFSUserBuilder;

/**
 *
 * @author Matthew Eavenson <durandal@uga.edu>
 */
public class VFSUserToHomeDirectoryManagerImpl implements VFSUserToHomeDirectoryManager{
    
    private VFSAssociationManager<VFSUser, VFSNode> am;
    
    public VFSUserToHomeDirectoryManagerImpl(Connection conn){
        VFSNodeBuilder nBuilder = new VFSNodeBuilder();
        VFSUserBuilder uBuilder = new VFSUserBuilder();
        am = new VFSAssociationManagerImpl<VFSUser, VFSNode>(conn, uBuilder, nBuilder, "vfsUser", null, "home");
    }
    
    @Override
    public Iterator<VFSUser> getUsers(VFSNode node, VFSFilter filter) {
        return am.findTM1(node, filter);
    }

    @Override
    public VFSNode getHomeDirectory(VFSUser user) {
        return am.findUM1(user);
    }

    @Override
    public void setHomeDirectory(VFSUser user, VFSNode directory){
        am.persistM1(user, directory);
    }
    
}
